package com.example.app2.viewpager;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.example.app2.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class Ad extends PagerAdapter {
    public int[] listint = {R.drawable.g1,R.drawable.g2,R.drawable.g3};
    private Context mcontext;
    public List<View> list = new ArrayList<>();
    public Ad(Context mcontext){
        this.mcontext = mcontext;
        for (int i = 0; i < listint.length; i++) {
            View inflate = LinearLayout.inflate(mcontext, R.layout.veiwpager, null);
            ImageView imageView = inflate.findViewById(R.id.imageView);
            RadioGroup radioGroup = inflate.findViewById(R.id.radio);

            imageView.setImageResource(listint[i]);

            ((RadioButton)radioGroup.getChildAt(i)).setChecked(true);
            list.add(inflate);
        }

    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull @NotNull View view, @NonNull @NotNull Object object) {
        return view == object;
    }

    @NonNull
    @NotNull
    @Override
    public Object instantiateItem(@NonNull @NotNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
        container.removeView(list.get(position));
    }
}
